package day0213;

import java.util.Scanner;

public class ArrayDemo {

    public static void main(String[] args) {
        /*
            删除数组中的元素
         */
        int[] arr = {1, 2, 3, 4, 5, 6};

        Scanner in = new Scanner(System.in);

        System.out.println("请输入要删除元素的下标: ");
        int index = in.nextInt(); // 2

        int[] arr1 = new int[arr.length - 1];

//        for (int i = 0; i < arr.length - 1; i++) {
//            if (i >= index){
//                arr1[i] = arr[i + 1];
//            } else {
//                arr1[i] = arr[i];
//            }
//        }

        for (int i = 0, start = 0; i < arr.length; i++) {
            if (i != index) {
                arr1[start ++] = arr[i];
            }
        }

        // 遍历
        for (int i = 0; i < arr1.length; i++) {
            System.out.print(arr1[i] + ", ");
        }
    }

}
